package com.yuexun.dhdoctor.module.Government;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuexun.dhdoctor.module.Chartered.ui.Act_Chartered;
import com.yuexun.banner.Banner;
import com.yuexun.banner.BannerAdapter;
import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.config.Contracts;
import com.yuexun.dhdoctor.module.Government.adapter.MenuAdapter;
import com.yuexun.dhdoctor.module.Government.bean.BannerBean;
import com.yuexun.dhdoctor.module.departmentDocumentNew.Act_Document_New_New;
import com.yuexun.dhdoctor.module.email.ui.Act_MailMain;
import com.yuexun.dhdoctor.module.main.bean.MenuItemBean;
import com.yuexun.dhdoctor.module.meeting.ui.Act_MeetingCheck;
import com.yuexun.dhdoctor.module.meetingMaterial.Act_MeetingMaterialList;
import com.yuexun.dhdoctor.module.meetingNew.ui.Act_MeetingNew_Main;
import com.yuexun.dhdoctor.module.mythings.ui.Act_Mythings_New;
import com.yuexun.dhdoctor.module.personalPlan.ui.Act_PlanMain;
import com.yuexun.dhdoctor.module.survey.ui.Act_Survey_Main;
import com.yuexun.dhdoctor.module.webview.Act_WebView;
import com.yuexun.dhdoctor.util.ShowImageUtils;

import org.kymjs.kjframe.ui.SupportFragment;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by chenss on 2018/5/4 0004.
 */

public class Frag_Government extends SupportFragment {

    @Bind(R.id.government_menu)
    GridView governmentMenu;

    private Banner mBanner;
    private ArrayList<BannerBean> mDatas = new ArrayList<>();

    MenuAdapter menuAdapter;

    private Map<Integer, String> addressMap = new HashMap<Integer, String>() {
        {
            // 通知公告html
            put(0, AppConfig.WEB_H5_2 + "notice.html");
            // 医院文件html
            put(3, AppConfig.WEB_H5_2 + "hosfile.html");
            // 政府文件html
            put(4, AppConfig.WEB_H5_2 + "govfile.html");
            // 医院资讯html
            put(5, AppConfig.WEB_H5_2 + "news.html");
            // 常用电话html
            put(6, AppConfig.WEB_H5_2 + "cydh.html");
            // 院内投票html
            put(8, AppConfig.WEB_H5 + "hosvote.html");
        }
    };

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        View view = inflater.inflate(R.layout.frag_government, null);
        ButterKnife.bind(this, view);
        initBanner(view);
        initData();
        return view;
    }

    @Override
    protected void initData() {

        menuAdapter = new MenuAdapter(governmentMenu, Contracts.governmentMenuList, R.layout.item_menu);
        governmentMenu.setAdapter(menuAdapter);

        governmentMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MenuItemBean item = (MenuItemBean) parent.getItemAtPosition(position);
                Intent intent;
                switch (item.getPosition()) {
                    //事项审批
                    case 0:
                        intent = new Intent(getActivity(), Act_Mythings_New.class);
                        startActivity(intent);
                        break;
                    //通知公告
                    case 1:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(0) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        startActivity(intent);
                        break;
                    //收件箱
                    case 2:
                        intent = new Intent(getActivity(), Act_MailMain.class);
                        startActivity(intent);
                        break;
                    //计划日程
                    case 3:
                        intent = new Intent(getActivity(), Act_PlanMain.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("show", "1");
                        intent.putExtras(bundle);
                        startActivity(intent);
                        break;
                    //医院文件
                    case 4:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(3) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        startActivity(intent);
                        break;
                    //政府文件
                    case 5:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(4) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        startActivity(intent);
                        break;
                    //医院资讯
                    case 6:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(5) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        startActivity(intent);
                        break;
                    //会议信息
                    case 7:
                        intent = new Intent(getActivity(), Act_MeetingNew_Main.class);
                        startActivity(intent);
                        break;
                    //会议材料
                    case 8:
                        intent = new Intent(getActivity(), Act_MeetingMaterialList.class);
                        startActivity(intent);
                        break;
                    //会议签到
                    case 9:
                        intent = new Intent(getActivity(), Act_MeetingCheck.class);
                        intent.putExtra("type", 1);
                        startActivity(intent);
                        break;
                    //常用电话
                    case 10:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(6) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        startActivity(intent);
                        break;
                    //部门文档
                    case 11:
                        intent = new Intent(getActivity(), Act_Document_New_New.class);
                        startActivity(intent);
                        break;
                    //院内投票
                    case 12:
                        intent = new Intent(getActivity(), Act_WebView.class);
                        intent.putExtra("url", addressMap.get(8) + "?sessionUuid=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.SESSION_ID)
                                + "&nameOrJobnum=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.JOB_ID)
                                + "&userId=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.USER_ID)
                                + "&departmentId=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.DEPARTMENTID)
                                + "&depId=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.DEPARTMENTID)
                                + "&depName=" + PreferenceHelper.readString(getActivity(), AppConfig.USER_INFO, AppConfig.DEPARTMENTNAME));
                        startActivity(intent);
                        break;
                    //院内调查
                    case 13:
                        intent = new Intent(getActivity(), Act_Survey_Main.class);
                        startActivity(intent);
                        break;
                    //执业查询
                    case 14:
                        intent = new Intent(getActivity(), Act_Chartered.class);
                        startActivity(intent);
                        break;
                    default:
                        break;
                }
            }
        });
    }

    private void initBanner(View parentView) {
        mBanner = (Banner) parentView.findViewById(R.id.id_banner);

        BannerAdapter adapter = new BannerAdapter<BannerBean>(mDatas) {
            @Override
            protected void bindTips(TextView tv, BannerBean bannerModel) {
                tv.setText(bannerModel.getTips());
            }

            @Override
            public void bindImage(ImageView imageView, BannerBean bannerModel) {
                ShowImageUtils.showImageView(getActivity(), Integer.valueOf(bannerModel.getImageUrl()), "", imageView);
            }

        };

        mBanner.setBannerAdapter(adapter);
        getData2();
    }

    private void getData2() {
        mDatas.clear();
        BannerBean model = null;
        model = new BannerBean();
//        model.setImageUrl("http://183.131.151.199/health/resources/images/banner/banner1.png");
        model.setImageUrl(String.valueOf(R.drawable.banner1));
        model.setTips("服务专业化");
        mDatas.add(model);
        model = new BannerBean();
//        model.setImageUrl("http://183.131.151.199/health/resources/images/banner/banner2.png");
        model.setImageUrl(String.valueOf(R.drawable.banner2));
        model.setTips("工作高效化");
        mDatas.add(model);
        model = new BannerBean();
//        model.setImageUrl("http://183.131.151.199/health/resources/images/banner/banner3.png");
        model.setImageUrl(String.valueOf(R.drawable.banner3));
        model.setTips("模式现代化");
        mDatas.add(model);
        mBanner.notifiDataHasChanged();
    }
}
